#ifndef _BACKDROP_NUMBER_FX_H_
#define _BACKDROP_NUMBER_FX_H_

#include "backdrop_sfx.h"
#include "ui/ui_number.h"

namespace backdrop
{
class BackdropNumberFXSet;

class	BackdropNumberFXEntry
{
public:			
							BackdropNumberFXEntry();
	virtual					~BackdropNumberFXEntry();
	virtual void			Reset(int Number, int DigitC, const math::Vec2& From, const math::Vec2& To, float Time);
	virtual void			SetupWave(float Speed, float Offset, float Amplitude);
	virtual void			OnCreation() {};
	virtual void			OnArrival();
	bool					IsValid() { return m_CurrentTime > 0; };
	virtual bool			Tick(float dt);
	
	const math::Vec2&		GetPos() const { return m_Pos; };
	int						GetNumber() const { return m_Number; };
	int						GetDigitC() const { return m_DigitC; };
	COLOR					GetColor() const { return m_Color; };
	float					GetFraction() const { return 1.0f - (m_CurrentTime / m_MaxTime); };

	void					SetBackgdropSFXSet(BackdropNumberFXSet*	pBackgdropSFXSet) { m_pBackgdropSFXSet = pBackgdropSFXSet; };
	void					SetColor(COLOR c) { m_Color = c; }

protected:
	BackdropNumberFXSet*	m_pBackgdropSFXSet;
	int						m_Number;
	int						m_DigitC;
	math::Vec2				m_From, m_To, m_Pos;
	float					m_CurrentTime, m_MaxTime;
	COLOR					m_Color;

	// wave pattern
	float					m_Speed, m_Offset, m_Amplitude;
};

class	BackdropNumberFXSet : public BackgdropSFXSet
{
public:
								BackdropNumberFXSet(camera::AbstractCamera* pCam, BackdropSFX* pParent);
	virtual						~BackdropNumberFXSet();
	virtual	void				Render();
	virtual void				Tick(float dt);
	virtual void				Load(const std::string& File, int MaxNumber);
			void				AddNumber(int Number, const math::Vec2& From, const math::Vec2& To, COLOR Color = -1);
			void				Setup(const math::Vec2& Time, const math::Vec2& Speed, const math::Vec2& Amplitude, bool Fade = false);
protected:
	virtual void				FillNumber(BackdropNumberFXEntry*	pNum, int Number, const math::Vec2& From, const math::Vec2& To);
	virtual void				CreateSet(int Max);
	ui::UINumber				m_Number;
	int							m_MaxNumberC;
	int							m_ActiveNumberC;
	int							m_NumberI;
	BackdropNumberFXEntry*		m_NumberA;
	float						m_Time;

	math::Vec2					m_MoveTime;
	math::Vec2					m_MoveSpeed;
	math::Vec2					m_MoveAmplitude;
	bool						m_Fade;

	static const int			BUFFER_SIZE	= 1000;
	Graphics::Vertex2D*			m_BufferA;
	int							m_VertexC;
	void						FlushBuffer();

};
}  // namespace backdrop

#endif // _BACKDROP_NUMBER_FX_H_
